package com.example.renyang.soaptest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void getpro(View view){
        new Thread(){
            @Override
            public void run(){
                String url="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl";
		        String ns="http://WebXml.com.cn";
		        String action="getRegionProvince";
		        HttpTransportSE trans=new HttpTransportSE(url);
		        SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
                SoapObject body=new SoapObject(ns, action);
		        envelope.setOutputSoapObject(body);
		        envelope.dotNet=true;
                SoapObject so= null;
                try {
                    trans.call(ns+"/"+action, envelope);
                    System.out.println(envelope.bodyIn.getClass().getName());
                    System.out.println(envelope.getResponse().getClass().getName());
                    so = (SoapObject)envelope.getResponse();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                }

                for(int i=0;i<so.getPropertyCount();i++){
			        Log.i("SOAP",so.getProperty(i).toString());
		        }

            }
        }.start();
    }
}
